module;

#include <boost/asio/ip/tcp.hpp>

export module Mqtt;
import std;
import Config;

using namespace boost;
using tcp = asio::ip::tcp;

export namespace Mqtt {
	class Server {
	private:
		std::ostream& log = std::clog;
		std::ostream& err = std::cerr;
		asio::io_context ioc;
		tcp::acceptor acceptor;
		tcp::iostream stream_mqtt;
	public:
		Server() :
			acceptor(ioc, tcp::endpoint(tcp::v4(), 1883))
		{

		}
		void tryAccept() {
			log << Config::try_accept << std::endl;
			stream_mqtt.socket() = acceptor.accept();
			log << Config::yes_accept << std::endl;
		}
		void readOne() {
			while (true) {
				char c = stream_mqtt.get();
				if (!stream_mqtt)
					break;
				std::cout.put(c);
			}
			std::cout << std::endl;
		}
		void start() {
			while (true) {
				tryAccept();
				readOne();
			}

		}
	};
}